from django.contrib.auth.models import User, AbstractUser
from django.db import models

# Create your models here.

class Rules(models.Model):
    name = models.CharField(max_length=20,verbose_name='违规分类')
class Customer(AbstractUser):
    status_checks = [
        ('启用', '启用'),
        ('禁用', '禁用')
    ]
    gategory_checks = [
        ('普通用户','普通用户'),
        ('作者','作者'),
        ('管理员','管理员')
    ]
    nicheng = models.CharField(max_length=20,verbose_name='昵称')
    headimg = models.ImageField(default='default.jpg', upload_to='headimg',verbose_name='用户头像')
    jianjie = models.TextField(max_length=100,verbose_name='简介')
    status = models.CharField(max_length=4,choices=status_checks, default='启用',verbose_name='用户状态')
    gategory = models.CharField(max_length=6,choices=gategory_checks,verbose_name='用户分类')
    rules = models.ForeignKey(Rules,on_delete=models.CASCADE,verbose_name='违规',related_name='customers',default=2)

class StoreGategory(models.Model):
    name = models.CharField(max_length=10)
    def __str__(self):
        return self.name

class Store(models.Model):
    status_check=[
        ('已审核','已审核'),
        ('未审核','未审核')
    ]
    title = models.CharField(max_length=100,verbose_name='故事标题')
    gategory = models.ManyToManyField(StoreGategory,verbose_name='分类')
    content = models.TextField(verbose_name='内容')
    date = models.DateField(verbose_name='日期',auto_now_add=True)
    status = models.CharField(max_length=6,choices=status_check,default='未审核',verbose_name='审核状态')
    likes = models.IntegerField()
    read = models.IntegerField()
    author = models.ForeignKey(Customer,on_delete=models.CASCADE,verbose_name='作者',related_name='stores')
    share = models.ForeignKey(Customer,on_delete=models.CASCADE,verbose_name='分享用户')
    rules = models.ForeignKey(Rules, on_delete=models.CASCADE, verbose_name='违规',related_name='stores')

class Comment(models.Model):
    status_check = [
        ('已审核', '已审核'),
        ('未审核', '未审核')
    ]
    user = models.ForeignKey(Customer,on_delete=models.CASCADE,verbose_name='评论用户',related_name='comments')
    store = models.ForeignKey(Store,on_delete=models.CASCADE,verbose_name='关联故事',related_name='comments')
    content = models.TextField(verbose_name='评论内容')
    status = models.CharField(max_length=6,choices=status_check,default='未审核')
    rules = models.ForeignKey(Rules, on_delete=models.CASCADE, verbose_name='违规',related_name='comments')
    date = models.DateField(verbose_name='评论时间',auto_now_add=True,null=True)

class UserBack(models.Model):
    user = models.CharField(max_length=20,verbose_name='反馈用户的姓名')
    date = models.DateField(verbose_name='反馈日期')
    content = models.TextField(verbose_name='反馈内容')
    email = models.EmailField(verbose_name='反馈者的邮箱')


